package org.example.springboot.service.impl;

import org.example.springboot.dao.SalesDAO;
import org.example.springboot.dao.impl.SalesDAOImpl;
import org.example.springboot.entity.PageEntity;
import org.example.springboot.entity.Sales;
import org.example.springboot.service.Salesservice;

import java.util.List;

public class SalesserviceImpl implements Salesservice {

    private SalesDAO salesDAO = new SalesDAOImpl();

    @Override
    public PageEntity<Sales> findSalesPage(Integer current, Integer pageSize) {
        int total = salesDAO.selectsalesCount();
        List<Sales> sales = salesDAO.salesLimit((current - 1) * pageSize,pageSize);
        PageEntity<Sales> pageEntity = new PageEntity<>();
        pageEntity.setCurrent(current);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setRecords(sales);
        return pageEntity;
    }

    @Override
    public List<Sales> findAll() {
        return salesDAO.setAll();
    }

    @Override
    public Sales findByid(String id) {
        return salesDAO.selectByid(id);
    }

    @Override
    public boolean save(Sales sales) {
        return salesDAO.inser(sales);
    }

    @Override
    public boolean delete(String id) {
        return salesDAO.delete(id);
    }

    @Override
    public boolean update(Sales sales) {
        return salesDAO.update(sales);
    }
}
